home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 13.5 KB | 377 lines | [TEXT/MPS ] |
- // UMacAppGlobals.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UMACAPPGLOBALS__
- #define __UMACAPPGLOBALS__
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __UCLASSDESC__
- #include "UClassDesc.h"
- #endif
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- // Toolbox
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __NOTIFICATION__
- #include <Notification.h>
- #endif
-
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
-
- // For ExitToShell
- #ifndef __SEGLOAD__
- #include <SegLoad.h>
- #endif
-
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
-
- // ANSI
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TObject;
- class TPrintHandler;
- class TView;
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations
- //----------------------------------------------------------------------------------------
-
- extern TextStyle gSystemStyle;
- // System's default text style
-
- extern TextStyle gApplicationStyle;
- // Application's default text style
-
- extern TextStyle gApplicationStyle9;
- // Application's default text style, 9 Point
-
- extern WindowRef gWorkPort;
- // Pointer to a window that is created during initialization, but never shown or
- // enumerated.
-
- extern RgnHandle gTemporaryRegion;
- // gTemporaryRegion is a temporary RgnHandle created in InitUMacApp. When debugging: before
- // using gTemporaryRegion, call UseTemporaryRegion and when done call DoneWithTemporaryRegion; this ensures
- // that 2 routines do not try to use gTemporaryRegion and the same time
-
- extern NMRecPtr gNotificationPtr;
- // Passed to all occurrences of AEInteractWithUser. Initialized to NULL so the
- // AppleEvent manager will provide default notification behavior. Point it at
- // your own custom notification record if you want other behavior
-
- extern ModalFilterYDProcPtr gModalFilterYDProcPtr;
- // Default returnval for SFPut/GetParms. Initialized to MacAppStandardFileFilter.
-
- #if qDebug
- extern Boolean gBusyTemporaryRegion;
- // Is gTemporaryRegion in use?
-
- extern CStr255 gUsedBy;
- // The routine using gTemporaryRegion
- #endif
-
- //----------------------------------------------------------------------------------------
- // Manage a temporary region
- //----------------------------------------------------------------------------------------
- class CTemporaryRegion
- {
- protected:
- static RgnHandle fCachedRgn; // the single level region cache
-
- FailInfo fFailInfo; // the failure record that references
- // the failure handling method
-
- RgnHandle fRgnHandle; // the temp region
-
- protected:
- void* operator new(size_t size); // prohibit "new CTemporaryRegion"
- void operator delete(void* obj); // avoid compiler warnings
-
- public:
- CTemporaryRegion();
- // Allocates the fRgnHandle and installs the failure handler.
-
- ~CTemporaryRegion();
- // Deallocates the fRgnHandle and removes the failure handler.
-
- void Cleanup();
-
- static void CallCleanup(void* context);
-
- //------------------------------------------------------------------------------------
- // Conversion operator methods
- //------------------------------------------------------------------------------------
-
- operator RgnHandle() { return fRgnHandle; }
- // Conversion operator, for converting CTemporaryRegion to a RgnHandle.
- };
-
- //----------------------------------------------------------------------------------------
- // These are really private, but they're here in case access is needed.
- //----------------------------------------------------------------------------------------
-
- extern FailInfo pFi; // Outermost failure handler
-
-
- //----------------------------------------------------------------------------------------
- // Debugging
- //----------------------------------------------------------------------------------------
-
- #if qDebug
- void DoneWithTemporaryRegion();
- // Indicates that gTemporaryRegion is no longer in use. Call this only if qDebug is true.
-
- void EnterDebugger(Boolean entering);
- // Call to enter the MacApp Debugger
-
- void UseTemporaryRegion(const CStr255& byWhom);
- // Call this when you are about to use gTemporaryRegion and qDebug is true. Used with
- // DoneWithTemporaryRegion will prevent you from trying to use gTemporaryRegion from two places at the
- // same time.
-
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Windows
- //----------------------------------------------------------------------------------------
-
- Boolean ParseTitleTemplate(CStr255& itsTemplate,
- short& preDocname,
- short& constTitle);
- // Used in TWindow::IWindow to parse the template for window titles. Returns true if it
- // changed the template. preDocname is start of document name in CString; constChars is
- // total # characters of window title that are constants. (These values are fixed
- // regardless of the document name.) If preDocname is 0, then the entire title is
- // constant.
-
- Boolean SubstituteInTitle(CStr255& title,
- const CStr255& newStuff,
- short preDocname,
- short constTitle);
- // Substitutes newStuff into the template as parsed by ParseTitleTemplate; returns true if
- // a substitution was made.
-
-
- //----------------------------------------------------------------------------------------
- // Object Creation Utilities
- //----------------------------------------------------------------------------------------
-
- void RegisterStdType(const CStr255& typeName, IDType signature);
- // Associates the given class with a signature.
-
- IDType GetStandardType(const ClassDesc* itsClassDesc);
- // Return the signature for the given class.
-
- const ClassDesc* GetClassDescFromSignature(IDType signature);
- // Returns the class descriptor associated with a given signature, or NULL
-
- const ClassDesc* DetermineClassDesc(IDType signature, const ClassName& className);
- // Returns the ClassDesc associated with the given class name, if className is not
- // empty. Returns the ClassDesc associated with the given signature, if className is
- // empty
-
- TObject* NewStdObject(IDType signature);
- // Returns the prototype object for the given signature.
-
- TObject* NewObjectBySignature(IDType signature,
- const ClassName& className);
- // Returns an instance of class "className" if className is non-empty. Returns the
- // prototype object for the given signature if className is empty
-
-
- //----------------------------------------------------------------------------------------
- // Initialization code that needs to always be compiled for 68000.
- //----------------------------------------------------------------------------------------
-
- // void InitUMacApp(short callsToMoreMasters);
- // Initialize the UMacApp unit.
- // Call this in your program after calling InitToolBox and ValidateConfiguration.
- // InitUMacApp is now a macro. The code formerly contained in the InitUMacApp routine has
- // been split into three parts: InitUMacApp_Step1, InstallFailureHandler, and
- // InitUMacApp_Step3. The reason for splitting up InitUMacApp is that on PowerPC the outermost
- // failure handler must be set up in the main program so that the address saved by setjmp in Try
- // is part of the call chain. This code was moved into a macro called InstallFailureHandler.
- // InstallFailureHandler _MUST_ be called from main for PowerPC.
-
- #define InitUMacApp(callsToMoreMasters) \
- InitUMacApp_Step1(); \
- \
- /* Install the permanent Outermost failure handler */ \
- InstallFailureHandler; \
- \
- InitUMacApp_Step3(callsToMoreMasters);
-
- #define InstallFailureHandler \
- pFi.Reset(); /* ensure that pFi is in an initial state */ \
- Try(pFi) \
- { } \
- else { \
- if (pFi.error != noErr) { /* check to see if an alert has already been displayed */ \
- if (pFi.message == 0) \
- pFi.message = messageInitializationFailed; /* if no message specified, use our own */ \
- ErrorAlert(pFi.error, pFi.message); \
- } \
- ExitToShell(); \
- }
-
- void InitUMacApp_Step1();
- void InitUMacApp_Step3(short callsToMoreMasters);
-
- //----------------------------------------------------------------------------------------
- // Miscellaneous
- //----------------------------------------------------------------------------------------
-
- void DoAlertKeyDown(DialogRef theDialog, short itemNo);
- // Given a dialog pointer and button item, simulate pressing the button
-
- void DoInitUMacApp();
- // Should be called only by InitUMacApp. It is here because this doesn't need to be
- // universal code but InitUMacApp does.
-
- void GetAlertButtonTitle(DialogRef theDialog, short itemNo, CStr255& theTitle);
- // Given a dialog pointer and a button item, return the title of that button
-
- Boolean CompareAlertKeysToItem(DialogRef theDialog, const CStr2& theChars, short& itemHit);
- // Compares the multi-byte char to the first character of each button title
- // 1st button in alert (by convention == "OK"). 2nd button in alert (by convention ==
- // "Cancel"). 3rd button in alert (by convention == "No")
-
- void DrawDefaultProc(DialogRef dlog);
- // Used by the MinimalAlertFilter to draw the bold outline around the default button
-
- pascal Boolean MinimalAlertFilter(DialogRef theDialog, EventRecord& theEvent, short& itemHit);
- // MacApp's minimal alert filter; handles return & enter, command-. and escape, and
- // draws the bold outline around the default button
- // NOTE: Left with pascal keyword so it could continue to be used with the Toolbox
- // Dialog Manager.
-
- pascal Boolean MacAppAlertFilter(DialogRef theDialog,
- EventRecord& theEvent,
- short& itemHit);
- // Default alert filter used throughout MacApp. Lets you answer yes and no to dialogs
- // with keystrokes. Handles "command-." and escape. If the alert has not been called in a
- // failure sequence then the application also handles update and activate events and
- // idles.
- // NOTE: Requires pascal keyword for use with the Toolbox Dialog Manager.
-
- pascal Boolean MacAppAppleEventIdleProc(EventRecord& theEventRecord,
- long& sleepTime,
- RgnHandle& mouseRgn);
- // Default AppleEvent idle proc used throughout MacApp. Handles update and activate events
- // NOTE: Requires pascal keyword for use with the Apple Event Manager.
-
- pascal Boolean MacAppStandardFileFilter(DialogRef theDialog, EventRecord* theEvent,
- short* itemHit, void *yourDataPtr);
- // Default Filter proc for Standard File dialogs. Handles update and activate events
- // NOTE: Requires pascal keyword for use with Standard File.
-
- void ApplicationBeep();
- // If gApplication is not NULL just calls gApplication->Beep else it does a SysBeep.
- // Removes a circular reference for UFailure.
-
- DialogRef GetNewCenteredDialog(ResNumber dialogID,
- Ptr dStorage,
- WindowRef behind);
- // The same as GetNewDialog except it centers the dialog on the screen and sets the
- // cursor to an arrow.
-
- void GetTextStyleFontInfo(const TextStyle& theTextStyle,
- FontInfo& theFontInfo,
- short& theFontHeight);
- // Returns the FontInfo record for the font/ face/ size specified in theTextStyle. Uses a
- // temporary port so you don't have to. Also returns the font's line height.
-
- void ExitMacApp();
- // Call this if for some reason you want to immediately exit the application. It calls
- // gApplication->Terminate, cleans up some other internal stuff, and then calls
- // ExitToShell. (Normally, you would not call this, because MacApp takes care of
- // terminating the application.)
-
- void InstallIfPrintHandler(TPrintHandler* aPrintHandler, TView* aView);
- // Install a clone of aPrintHandler into the view if aPrintHandler is not the same as
- // the NULL print handler. (Typically if printing is initialized.) This lets us install
- // a print handler if printing is being used in the application and do NOTHING if it
- // is not.
-
- RgnHandle MakeNewRgn();
- // Calls NewRgn, then FailNIL
-
- #ifdef __cplusplus
- extern "C" {
- #endif
- void CleanupMacApp (void);
- // Installed as an atexit procedure.
- #ifdef __cplusplus
- }
- #endif
-
- //==========================================================================================
- // The following routines are only supported for System 7
- //==========================================================================================
-
- OSErr GetSysVolume(short& vRefNum);
- // Get the vRefNum of the system (boot) volume
-
- OSErr GetIndVolume(short index,
- short& vRefNum);
- // Get the vRefNum of an indexed on-line volume
-
- OSErr VolHasDesktopDB(short vRefNum,
- Boolean& hasDesktop);
- // Check if a volume supports desktop DB calls
-
- OSErr FindAppOnVolume(OSType sig,
- short vRefNum,
- FSSpec& thefile);
- // Ask vol's desktop db for application
-
- OSErr LaunchAppByFSSpec(const FSSpec& fileSpec,
- LaunchFlags launchControlFlags,
- ProcessSerialNumber& psn);
- // Launch app given a fileSpec
-
-
- OSErr LaunchBySignature(OSType sig, // Signature of app
- ProcessSerialNumber& psn,// Returns PSN of app
- FSSpec * fileSpec, // Returns location of app (ignored if NULL)
- Boolean * launched, // Returns true if I had to launch (NULL ok)
- Boolean allowLaunch,// OK to launch it if not running?
- LaunchFlags launchControlFlags// Launch control flags; see Process Mgr
- );
- // Main routine. Find app, launching if need be
- #endif
-
-
-